<?php
namespace app\api\controller\wxapp;

use app\common\model\Signup as SignupModel;
use app\api\controller\Controller;


class Signup extends Controller {

    public function _initialize()
    {
        parent::_initialize();

    }
    public function add(){

        $this->request->filter(['strip_tags','htmlspecialchars']);
        $data=$this->request->param();

        if(empty($data)){
            return $this->renderError('无数据提交');
        }
        $condition['telephone']=$data['telephone'];
        $isExistId=SignupModel::where($condition)->value('id');
        if($isExistId){
            return $this->renderError('您已提交，请勿重复提交！');
        }
        $saveData['name']=$data['name'];
        $saveData['telephone']=$data['telephone'];
        $saveData['occupation']=$data['occupation'];
        $saveData['taste_of_wine']=$data['taste_of_wine'];
        $saveData['join_wine_party']=$data['join_wine_party'];
        $saveData['expectation']=$data['expectation'];
        $saveData['create_time']=time();

        $res=SignupModel::add($saveData);

        if($res!==false){
            return $this->renderSuccess([], '您的报名已提交成功！');
        } else {
            return $this->renderError('接口提交失败');
        }
    }
}